package com.yf.ability.config.controller;

import com.yf.ability.config.dto.CfgPropDTO;
import com.yf.ability.config.service.CfgPropService;
import com.yf.ability.log.annon.LogInject;
import com.yf.ability.log.enums.LogType;
import com.yf.base.api.api.ApiRest;
import com.yf.base.api.api.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* <p>
* 通用配置控制器
* </p>
*
* @author 聪明笨狗
* @since 2020-04-17 09:12
*/
@Api(tags={"通用配置"})
@RestController
@RequestMapping("/api/sys/config/prop")
public class CfgPropController extends BaseController {

    @Autowired
    private CfgPropService baseService;


    /**
     * 添加或修改
     * @param reqDTO
     * @return
     */
    @LogInject(title="保存上传配置", logType = LogType.SYSTEM)
    @ApiOperation(value = "添加或修改")
    @PostMapping("/save")
    public ApiRest save(@RequestBody CfgPropDTO reqDTO) {
        baseService.save(reqDTO);
        return super.success();
    }

    /**
     * 查找详情
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "查找详情")
    @PostMapping("/detail")
    public ApiRest<CfgPropDTO> detail(@RequestBody CfgPropDTO reqDTO) {

        String provider = reqDTO.getProvider();
        String type = reqDTO.getType();

        if(StringUtils.isBlank(provider)){
            provider = "default";
        }

        CfgPropDTO dto = baseService.detail(type, provider);
        System.out.println(dto);
        return super.success(dto);
    }
}
